from ..models.base_model import BaseModel
from ..models.student import Student
from ..models.classinfo import ClassInfo
from django.db import models
from datetime import date

# 学生班级关系
class StudentClassRelationship(BaseModel):
    """学生班级关系"""
    student = models.ForeignKey(Student, on_delete=models.CASCADE, related_name='class_relationships', verbose_name="学生")
    class_id = models.ForeignKey(ClassInfo, on_delete=models.CASCADE, related_name='student_relationships', verbose_name="班级")
    enrollment_date = models.DateField(default=date.today, verbose_name="入学日期")
    exit_date = models.DateField(null=True, blank=True, verbose_name="离校日期")

    def __str__(self):
        return f"{self.student} - {self.class_id}"

    class Meta:
        verbose_name = "学生班级关系"
        verbose_name_plural = "学生班级关系"
        unique_together = ('student', 'class_id')